package com.xieke.admin.util;

import com.xieke.admin.dto.UserInfo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Component;

/**
 *
 * Shiro权限标签帮助类
 *
 */
@Component
public class ShiroTagUtil {

	/**
	 * 是否拥有该权限
	 * @param permission  权限标识
	 * @return   true：是     false：否
	 */
	public boolean hasPermission(String permission) {
		Subject subject = SecurityUtils.getSubject();
		return subject != null && subject.isPermitted(permission);
	}

	/**
	 * 是否拥有该角色
	 * @param role  角色标识
	 * @return   true：是     false：否
	 */
	public boolean hasRole(String role) {
		return ((UserInfo) SecurityUtils.getSubject().getPrincipal()).getRoleInfo().getRoleCode().equals(role);
	}

	public String getUserName() {
		return ((UserInfo) SecurityUtils.getSubject().getPrincipal()).getUserName();
	}

}